/*package com.suning.sawp.web.controller;

import java.lang.reflect.InvocationTargetException;
import java.security.Principal;
import java.util.List;
import java.util.Map;

import javax.validation.Valid;

import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.suning.nsf.istore.geography.dto.GeoCityDTO;
import com.suning.nsf.istore.geography.dto.GeoDistDTO;
import com.suning.nsf.istore.geography.dto.GeoStoreDTO;
import com.suning.nsf.istore.geography.dto.GeoStreetDTO;
import com.suning.nsf.istore.inpt.dto.InptRequest;
import com.suning.nsf.istore.inpt.dto.ResponseForMobile;
import com.suning.nsf.istore.inpt.po.InterestPointBaseInfo;
import com.suning.nsf.istore.inpt.service.intf.InptInfoRemoteBusinessSV;
import com.suning.sawp.dto.storeman.JsonResult;
import com.suning.sawp.dto.storeman.SaveInputParam;
import com.suning.sawp.exception.InptException;
import com.suning.vgs.follow.remote.intf.StoreManRemoteService;

*//**
 * 
 * 
 * 兴趣点
 * 
 * @author helobuya@Gmail.com
 * 
 *//*
@RequestMapping("inpt")
@Controller
public class InptController {

    private static Logger logger = LoggerFactory.getLogger(InptController.class);

    @Autowired
    StoreManRemoteService storeManRemoteService;

    @Autowired
    InptInfoRemoteBusinessSV inptInfoRemoteserviceClient;

    *//**
     * 新增兴趣点草稿 <br>
     * TODO 调马力hessian接口
     * 
     * @param
     * @return
     * 
     *         <pre>
     * 返回数据:
     * 		retFlag:		返回状态码（0-失败，1-成功），
     * 		errorCode:		错误码，
     * 		errorMessage:	错误描述信息
     * 		data:			返回新增成功的兴趣点id
     *         </pre>
     * 
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     *//*
    @ResponseBody
    @RequestMapping(value = "save.do", produces = "application/json; charset=utf-8")
    public JsonResult save(@Valid SaveInputParam saveInputParam, Principal principal) throws Exception {

        if (logger.isDebugEnabled()) {

            logger.debug("save {}", JSON.toJSONString(saveInputParam));

        }
        InptRequest inptRequest = new InptRequest();
        saveInputParam.setCollectorNum(principal.getName());
        BeanUtils.copyProperties(inptRequest, saveInputParam);
        ResponseForMobile responseForMobile = inptInfoRemoteserviceClient.addInpt(inptRequest);
        return new JsonResult(responseForMobile.getRetFlag(), responseForMobile.getErrorCode(),
                responseForMobile.getErrorMessage(), responseForMobile.getData());

    }

    *//**
     * 修改兴趣点草稿
     * 
     * @param saveInputParam
     * @return
     * 
     *         <pre>
     * 返回数据:
     * 	retFlag:返回状态码（0-失败，1-成功），
     * 	errorCode:错误码，
     * 	errorMessage:错误描述信息
     *         </pre>
     * 
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     *//*
    @ResponseBody
    @RequestMapping(value = "update.do", produces = "application/json; charset=utf-8")
    public JsonResult update(SaveInputParam saveInputParam, @RequestParam Integer id, Principal principal)
            throws Exception {
        InptRequest inptRequest = new InptRequest();
        saveInputParam.setCollectorNum(principal.getName());
        inptRequest.setId(id);
        BeanUtils.copyProperties(inptRequest, saveInputParam);
        ResponseForMobile responseForMobile = inptInfoRemoteserviceClient.updateInpt(inptRequest);
        return new JsonResult(responseForMobile.getRetFlag(), responseForMobile.getErrorCode(),
                responseForMobile.getErrorMessage(), responseForMobile.getData());

    }

    *//**
     * 
     * 查询我的草稿
     * 
     * <pre>
     * 上传参数 :
     * 	collectorNum:客户端登录人工号
     * 	start:开始序号
     * 	limit:一次加载数目
     * </pre>
     * 
     * @return
     * 
     *         <pre>
     * 返回数据:
     * 	retFlag:返回状态码（0-失败，1-成功），
     * 	errorCode:错误码，
     * 	errorMessage:错误描述信息
     * 	data:list类型gson
     * 	id:兴趣点id
     * 	name:兴趣点名称
     * 	provinceCode:兴趣点省份编码
     * 	provinceName:兴趣点省份名称
     * 	cityCode:城市编码
     * 	cityName: 城市名称
     * 	districtCode：区编码（可选）
     * 	districtName: 区名称（可选）
     * 	streetCode：街道编码（可选）
     * 	streetName: 街道名称（可选）
     * 	detailAddress:详细地址（可选）
     *         </pre>
     *//*
    @ResponseBody
    @RequestMapping(value = "queryMyDraft.do", produces = "application/json; charset=utf-8")
    public JsonResult queryMyDraft(Principal principal, @RequestParam(defaultValue = "0") Integer start,
            @RequestParam(defaultValue = "10") Integer limit) {

        GeoStoreDTO geoStoreDTO = getProvByStoreCode(principal.getName());

        List<InterestPointBaseInfo> inpts = inptInfoRemoteserviceClient.queryMyDraft(principal.getName(),
                geoStoreDTO.getMdmProvCode(), start, limit);

        return new JsonResult(inpts);

    }

    *//**
     * 批量删除我的草稿
     * 
     * <pre>
     * 	collectorNum:客户端登录人工号
     * 	数组 delIds:被删除兴趣点id数组集合
     * </pre>
     * 
     * @return
     * 
     *         <pre>
     * 返回数据：
     * 	retFlag:返回状态码（0-失败，1-成功），
     * 	errorCode:错误码，
     * 	errorMessage:错误描述信息
     *         </pre>
     * 
     *//*
    @ResponseBody
    @RequestMapping(value = "deleteMyDraft.do", produces = "application/json; charset=utf-8")
    public JsonResult deleteMyDraft(@RequestParam Integer[] delIds, Principal principal) {

        GeoStoreDTO geoStoreDTO = getProvByStoreCode(principal.getName());
        inptInfoRemoteserviceClient.batchDeleteMyDraft(delIds, geoStoreDTO.getMdmProvCode());
        return new JsonResult(null);

    }

    *//**
     * 查询我的责任兴趣点
     * 
     * <pre>
     * responsibilityCode:客户端登录人工号
     * 	start:开始序号
     * 	limit:一次加载数目
     * </pre>
     * 
     * @return
     * 
     *         <pre>
     * 返回数据：
     * 	retFlag:返回状态码（0-失败，1-成功），
     * 	errorCode:错误码，
     * 	errorMessage:错误描述信息
     * 	data:list类型gson
     * 		id：兴趣点id
     * 		name:兴趣点名称
     * 		provinceCode:兴趣点省份编码
     * 		provinceName:兴趣点省份名称
     * 		cityCode:城市编码
     * 		cityName: 城市名称
     * 		districtCode：区编码（可选）
     * 		districtName: 区名称（可选）
     * 		streetCode：街道编码（可选）
     * 		streetName: 街道名称（可选）
     * 		detailAddress:详细地址（可选）
     * 		startLevel:星级
     * 		otherName:常用名（"/"分割）
     * 		longitude:经度
     * 		latitude：纬度
     * 
     * 
     *         </pre>
     *//*

    @ResponseBody
    @RequestMapping(value = "queryMyRespInfo.do", produces = "application/json; charset=utf-8")
    public JsonResult queryMyRespInfo(Principal principal, @RequestParam(defaultValue = "0") Integer start,
            @RequestParam(defaultValue = "10") Integer limit) {

        String responsibilityCode = principal.getName();
        GeoStoreDTO geoStoreDTO = getProvByStoreCode(responsibilityCode);

        List<InterestPointBaseInfo> result = inptInfoRemoteserviceClient.queryMyRespInptInfo(responsibilityCode,
                geoStoreDTO.getMdmProvCode(), start, limit);

        return new JsonResult(result);

    }

    *//**
     * 区域id街道信息
     * 
     * <pre>
     * districtCode:区域id
     * </pre>
     * 
     * @return
     * 
     *         <pre>
     * retFlag:返回状态码（0-失败，1-成功），
     * 	errorCode:错误码，
     * 	errorMessage:错误描述信息
     * 	data: list类型gson{
     * 		streetCode：街道编码
     * 		streetName：街道名称
     * 	}
     * 
     * 
     *         </pre>
     *//*
    @ResponseBody
    @RequestMapping(value = "queryStreetInfoByDistId.do", produces = "application/json; charset=utf-8")
    public JsonResult queryStreetInfoByDistId(@RequestParam String districtCode) {

        GeoDistDTO dist = inptInfoRemoteserviceClient.queryAllTownsInDist(districtCode);

        List<Map<String, Object>> datas = Lists
                .newArrayList(Lists.transform(dist.getStreets(), new Function<GeoStreetDTO, Map<String, Object>>() {

                    @Override
                    public Map<String, Object> apply(GeoStreetDTO street) {
                        Map<String, Object> data = Maps.newHashMap();
                        data.put("streetCode", street.getLesStreetCode());
                        data.put("streetName", street.getStreetName());
                        return data;
                    }
                }));
        return new JsonResult(datas);

    }

    *//**
     * 
     * 查询省，市，区列表
     * 
     * @return
     * 
     *         <pre>
     * 返回数据：
     * 	retFlag:返回状态码（0-失败，1-成功），
     * 	errorCode:错误码，
     * 	errorMessage:错误描述信息
     * 	data:业务数据
     * 		provinceCode:兴趣点省份编码
     * 		provinceName:兴趣点省份名称
     * 		cityCode:城市编码
     * 		cityName: 城市名称
     * 		districtList：{
     * 			districtCode：区编码
     * 			districtName: 区名称
     * 		}
     * 
     * 
     *         </pre>
     *//*
    @ResponseBody
    @RequestMapping(value = "queryMyAddress.do", produces = "application/json; charset=utf-8")
    public JsonResult queryMyAddress(Principal principal) {

        // rms 工号->店员所在门店编码 dubbo

        GeoCityDTO geoCityDTO = inptInfoRemoteserviceClient
                .getLesByStoreCode(getStoreCodeByStaffId(principal.getName()));

        // 调用nsf接口
        Map<String, Object> data = Maps.newHashMap();
        data.put("provinceCode", geoCityDTO.getProvCode());
        data.put("provinceName", geoCityDTO.getProvName());
        data.put("cityCode", geoCityDTO.getLesCityCode());
        data.put("cityName", geoCityDTO.getCityName());
        data.put("districtList", Lists.newArrayList(
                Lists.transform(geoCityDTO.getDistricts(), new Function<GeoDistDTO, Map<String, Object>>() {
                    @Override
                    public Map<String, Object> apply(GeoDistDTO input) {
                        Map<String, Object> distric = Maps.newHashMap();
                        distric.put("districtCode", input.getLesDistCode());
                        distric.put("districtName", input.getDistName());
                        return distric;
                    }
                })));

        return new JsonResult(data);

    }

    *//**
     * 兴趣点接口异常处理类
     * 
     * @param th
     * @return
     *//*
    @ResponseBody
    @ExceptionHandler
    public JsonResult exceptionHandler(Throwable th) {

        if (th instanceof BindException) {
            return new JsonResult("0", "参数异常", th);
        } else if (th instanceof InptException) {
            return new JsonResult("0", th.getMessage(), th);
        }
        return new JsonResult("0", "Sorry! Internal error.", th);

    }

    private GeoStoreDTO getProvByStoreCode(String staffId) {
        GeoStoreDTO geoStoreDTO = inptInfoRemoteserviceClient.getProvByStoreCode(getStoreCodeByStaffId(staffId));

        if (null == geoStoreDTO) {
            throw new InptException("没有员工所在门店地理信息!");
        }

        return geoStoreDTO;
    }

    private String getStoreCodeByStaffId(String staffId) {
        return storeManRemoteService.getStoreCodeByStaffId(staffId);
    }

}
*/